package com.company.poker.channel;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

/**
 * Description of class.
 * Created 4/10/13 4:43 PM
 *
 * @author andrey.rodin@playtech.com
 */

public class CommunicationManager extends UntypedActor {
    private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
    private ClientHandler clientHandler;

    public CommunicationManager() {
    }

    public CommunicationManager(ClientHandler clientHandler) {
        this.clientHandler = clientHandler;
    }

    @Override
    public void onReceive(Object message) {
        System.out.println("CommunicationManager - "+message);
        log.info("Received CommunicationManager message: {}", message);
        ActorRef table = getContext().system().actorOf(new Props(TableActor.class));
        table.tell("RECEIVED !", getSelf());
    }

    @Override
    public void preStart() {
        super.preStart();
        System.out.println("CommunicationManager - started");

    }

    @Override
    public void postStop() {
        super.postStop();
        System.out.println("CommunicationManager - stopped");
    }

    public ClientHandler getClientHandler() {
        return clientHandler;
    }

    public void setClientHandler(ClientHandler clientHandler) {
        this.clientHandler = clientHandler;
    }
}
